﻿/// <reference path="jquery-vsdoc.js" />

function setTab(m, n) {
  var tli = document.getElementById("menu" + m).getElementsByTagName("li");
  var mli = document.getElementById("main" + m).getElementsByTagName("ul");
  for (i = 0; i < tli.length; i++) {
    tli[i].className = i == n ? "hover" : "";
    mli[i].style.display = i == n ? "block" : "none";
  }
}

// Cookie http://www.stilbuero.de/2006/09/17/cookie-plugin-for-jquery/
(function ($) {
  $.cookie = function (key, value, options) {
    if (arguments.length > 1) {
      var o = $.extend({}, $.cookieOptions, options);
      if (value === null || value === undefined) {
        value = '';
        o.expires = -1;
      }
      if (o.expires.constructor != Date) {
        var today = new Date();
        today.setDate(today.getDate() + o.expires);
        o.expires = today;
      }
      document.cookie =
				key + '=' + value +
				'; expires=' + o.expires.toUTCString() +
				(o.path ? '; path=' + (o.path) : '') +
				(o.domain ? '; domain=' + (o.domain) : '') +
				(o.secure ? '; secure' : '');
    } else {
      if (result = new RegExp(key + "=(.*?)(?:;|$)").exec(document.cookie))
        return decodeURIComponent(result[1]);
      return false;
    }
  };
  $.cookieOptions = {
    expires: 365,
    path: '/'
  }
})(jQuery);


function $D(str) { return decodeURIComponent(str); };
function $E(str) { return encodeURIComponent(str); };

//////////////////////////////////////////////////////////////////////////


//////////////////////////////////////////////////////////////////////////
// 临时书架
function FixBookScookie(title, url, name, time) {
  return "<li><span class=\"main1 point2 left\"></span><a title=\"" + $D(title) + "\" href=\"" + url + "\" target=\"_blank\">" + $D(name) + "(" + time + ")</a></li>";
}
function ShowBookStore(obj) {
  var scookie = $D(jQuery.cookie("bookstore_8x"));
  if (scookie == null || scookie == "" || scookie == "false") {
    jQuery(obj).append("<li><span class=\"main1 point2 left\"></span>暂无数据!</li>");
    return;
  }
  result = "";
  arr = scookie.split(";");
  for (i = 0; i < arr.length - 1; i++) {
    a_1 = arr[i].split("|");
    result = result + FixBookScookie(a_1[0], a_1[1], a_1[2], a_1[3]);
  }
  if (result == "") {
    b = result.split('|');
  }
  jQuery(obj).append(result);
}
function AddBookStore(title, url, name, time) {
  var scookie = $D(jQuery.cookie("bookstore_8x"));
  if (scookie == null || scookie == "" || scookie == "false") {
    result = $E(title + "|" + url + "|" + name + "|" + time + ";");
    jQuery.cookie("bookstore_8x", result);
    return;
  }
  result = title + "|" + url + "|" + name + "|" + time + ";";
  arr = scookie.split(";");
  count = 10;
  if (arr.length < 10) {
    count = arr.length - 1;
  }
  for (i = 0; i < count; i++) {
    a_1 = arr[i].split("|");
    if (name != a_1[2]) {
      result += a_1[0] + "|" + a_1[1] + "|" + a_1[2] + "|" + a_1[3] + ";";
    }
  }
  jQuery.cookie("bookstore_8x", $E(result));
}
function ShowBookMark(obj, bookid) {
  var temp = $D(jQuery.cookie("14x_BookMarkId=" + bookid));
  if (temp == null || temp == "" || temp == "false") {
    return;
  }
  // nodeid|cid|cname
  var result = temp.split("|");
  jQuery(obj).empty();
  jQuery(obj).append("<a href=\"/chapter/" + bookid + "-" + result[0] + "-" + result[1] + ".shtml\" target=\"_blank\">" + result[2] + "</a>");
}
function AddBookMark(bookid, nodeid, cid, cname) {
  // var date = new Date().toLocaleString()
  jQuery.cookie("14x_BookMarkId=" + bookid, $E(nodeid + "|" + cid + "|" + cname + " " + new Date().toLocaleString()));
}
function CleanBookStore(obj) {
  jQuery.cookie("bookstore_8x", result);
  jQuery(obj).empty();
  ShowMessage("您清空了临时书架.");
}

//////////////////////////////////////////////////////////////////////////
// 搜索
var nyDefault = "鸟眼全向智能搜索,收录超过20万热门资源!";
var focusFlag = false;
function inputFocus(e) {
  if (e.value == nyDefault) {
    e.value = '';
  }
  focusFlag = true;
}
function checkInput() {
  var e = document.getElementById("query");
  if (e.value == nyDefault) {
    e.value = "";
    return true;
  }
}
//////////////////////////////////////////////////////////////////////////
// 用户登陆
function Passport() {
  username = $E(jQuery("#username").attr("value"));
  password = jQuery("#password").attr("value");
  if (username == "" || password == "") {
    return false;
  }
  /*cusername = jQuery.cookie("ny_9x_username");
  if (!(cusername == null || cusername == "" || cusername == "false")) {
  if ($E(cusername) != username) {
  alert("严禁一个会员拥有多个账号,您的操作已被记录.系统将自动登出!");
  jQuery("#username").attr("value", $D(cusername));
  jQuery("#password").attr("value", "");
  return false;
  }
  }*/
  jQuery.cookie("ny_9x_usernameb", username);
  jQuery("#top_left").empty();
  jQuery("#top_left").append("<form id=form1><label>系统正在为您登陆...</label></form>");
  jQuery("#top_left").load("http://user.niaoyan.com/center/npassport.aspx?username=" + username + "&password=" + password);
  return false;
}
//////////////////////////////////////////////////////////////////////////
// 服务器书架
function AddUserBookMarkS(sid, u, n, g) {
  AddUserBookMark(sid, u, n, g);
  G("passport").src = "http://user.niaoyan.com/center/npassport.aspx?" + UrlSeed();
  //jQuery("#top_left").load("http://user.niaoyan.com/center/npassport.aspx?username=123");
}
function AddUserBookMark(sid, u, n, g) {
  G("xloader").src = "http://user.niaoyan.com/center/addbookmark.aspx?sonid=" + sid + "&url=" + u + "&name=" + encodeURI(n) + "&group=" + g + "&siteid=0" + UrlSeed();
  //  jQuery.get("http://user.niaoyan.com/center/addbookmark.aspx", { sonid: sid, url: u, name: n, group: g }, function (data) {
  //    ShowBookMarkState(data);
  //  });
}
function AddUserBookMarkC(sid, u, n, g) {
  G("xloader").src = "http://user.niaoyan.com/center/addbookmark.aspx?sonid=" + sid + "&url=" + u + "&name=" + encodeURI(n) + "&group=" + g + "&siteid=0" + UrlSeed();
  //  jQuery.get("http://www.niaoyan.com/user/addbookmark.aspx", { sonid: sid, url: u, name: n, group: g }, function(data) {
  //    ShowBookMarkState2(data);
  //  });
}
function ShowBookMarkState(state) {
  //  switch (state) {
  //    case "0":
  //      ShowMessage("免费书架添加成功!");
  //      break;
  //    case "1":
  //      ShowMessage("额外书架添加成功!");
  //      break;
  //    case "2":
  //      ShowMessage("您的积分不足够添加书架,请查看相关说明.");
  //      break;
  //    case "3":
  //      ShowMessage("您的书架已经超过系统最大值!");
  //      break;
  //    case "4":
  //      ShowMessage("您的积分已经不足给现有书签续费.");
  //      break;
  //    case "5":
  //      ShowMessage("添加错误,请先确认是否登陆?");
  //      break;
  //    default:
  //      return;
  //  }
  //  return;
  ShowMessage(state);
}
function ShowBookMarkState2(state) {
  //  switch (state) {
  //    case "0":
  //      alert("免费书架添加成功!");
  //      break;
  //    case "1":
  //      alert("额外书架添加成功!");
  //      break;
  //    case "2":
  //      alert("您的积分不足够添加书架,请查看相关说明.");
  //      break;
  //    case "3":
  //      alert("您的书架已经超过系统最大值!");
  //      break;
  //    case "4":
  //      alert("您的积分已经不足给现有书签续费.");
  //      break;
  //    case "5":
  //      alert("添加错误,请先确认是否登陆?");
  //      break;
  //    default:
  //      return;
  //  }
  //  return;
  alert(state);
}
//////////////////////////////////////////////////////////////////////////
// 消息输出
function ShowMessage(str) {
  html = "<div id='loader'><div align='center'><h2>" + str + "</h2></div><div align='center'>";
  html += "<img border='0' src='http://img.niaoyan.com/c/i/loader.gif' alt='Loading'/></div></div>";
  jQuery("#loader_container").empty();
  jQuery("#loader_container").append(html);
  jQuery("#loader_container").show();
  setTimeout("ShowMessageEnd()", 4000);
}
function ShowMessageEnd() {
  jQuery("#loader_container").hide();
}
//////////////////////////////////////////////////////////////////////////
// 下载模块
function ThunderClcik(url) {
  OnDownloadClick(url, "", location.href, "04893", 2, "", 4);
}
function FlashGetClcik(url) {
  FlashgetDown(url, 5647);
}
function NormalClcik(url) {
  window.location = url;
}
//////////////////////////////////////////////////////////////////////////
// 推荐模块
function RecBook(bookid) {
  //time = new Date().getTime();
  G("xloader").src = "http://user.niaoyan.com/ashx/click.aspx?id=" + bookid + "&act=rec"+ UrlSeed();
  ShowMessage("感谢您的支持.");
  G("passport").src = "http://user.niaoyan.com/center/npassport.aspx?" + UrlSeed();
  //jQuery.get("http://www.niaoyan.com/ashx/click.aspx", { id: bookid, act: "rec", time: time }, function (result) {
    //    if (result == 0) {
    //      ShowMessage("推荐成功!");
    //ShowMessage(result);
    
    //jQuery("#top_left").load("http://www.niaoyan.com/user/passport.aspx?username=123&time=" + time);
    //    } else {
    //      ShowMessage("推荐失败!是否登陆?还有推荐票么?是否操作过快?");
    //    }
  //});
}
function RecBook2(bookid) {
  //time = new Date().getTime();
  G("xloader").src = "http://user.niaoyan.com/ashx/click.aspx?id=" + bookid + "&act=rec"+ UrlSeed();
  alert("感谢您的支持.");
  G("passport").src = "http://user.niaoyan.com/center/npassport.aspx?" + UrlSeed();
  //jQuery.get("http://www.niaoyan.com/ashx/click.aspx", { id: bookid, act: "rec", time: time }, function (result) {
    //    if (result == 0) {
    //      alert("推荐成功!");
    //alert(result);    
    //jQuery("#top_left").load("http://www.niaoyan.com/user/passport.aspx?username=123&time=" + time);
    //    } else {
    //      alert("推荐失败!是否登陆?还有推荐票么?是否操作过快?");
    //    }
  //});
}
//////////////////////////////////////////////////////////////////////////
// 广告模块
function SetIsDone() {
  var a = jQuery.cookie("CK2312");
  if (a == 2) {
    jQuery.cookie("CK2312", 0);
    G("xloader").src = "http://user.niaoyan.com/ashx/click.aspx?act=ad&id=0" + UrlSeed();
    //jQuery.get("http://www.niaoyan.com/ashx/click.aspx", { act: "ad", id: "0" });
    document.body.onclick = "";
    ShowMessage("本站不与广告内容产生任何连带责任.");
    //time = new Date().getTime()
    //jQuery("#top_left").load("http://www.niaoyan.com/user/passport.aspx?username=123&time=" + time);
    G("passport").src = "http://user.niaoyan.com/center/npassport.aspx?" + UrlSeed();
  }
}
function Locker() {
  jQuery.cookie("CK2312", 0);
  document.body.onclick = "";
}
function log() {
  jQuery.cookie("CK2312", 2);
  document.body.onclick = function () {
    Locker();
  };
  var a = jQuery.cookie("CK2312");
  if (a == 2) {
    setTimeout("SetIsDone()", 7000);
  }
}
//////////////////////////////////////////////////////////////////////////
// 用户升级模块
//function UserLevelUp() {
//  if (confirm("升级为正式会员将消耗您1000积分,是否升级?")) {
//    jQuery.get("http://user.niaoyan.com/center/userlevelup.aspx", function (result) {
//      if (result == 1) {
//        alert("升级成功!");
//        time = new Date().getTime()
//        jQuery("#top_left").load("http://www.niaoyan.com/user/passport.aspx?username=123&time=" + time);
//      } else {
//        alert("升级失败,请先确认是否有足够多的积分.");
//      }
//    });
//  }
//}
//////////////////////////////////////////////////////////////////////////
// 页面载入完成

jQuery(document).ready(function () {
  jQuery("#loading").hide();
});

function UrlSeed() {
  return "&seed=" + Date.parse(new Date());
}

